#include <bits/stdc++.h>
using namespace std;
#define int long long

int n, r, used[18], p[18], frc[21], res[1000006];


void dfs(int i) {
	if (i == n + 1) {
		int sum = 0;
		for (int k = 1; k < n; ++k) {
			sum += p[k];
			if (sum <= p[k + 1]) return;
		}
		--r;
		if (r == 0) {
			for (int k = 1; k <= n; ++k) cout << p[k] << " \n"[k == n];
			exit(0);
		}
		return;
	}
	for (int j = 1; j <= n; ++j) {
		if (!used[j]) {
			used[j] = 1; p[i] = j;
			dfs(i + 1);
			used[j] = 0;
		}
	}
}

struct SGT {
	int res[1000006 * 4];
	#define ls(p) (p << 1)
	#define rs(p) (p << 1 | 1)
	void update(int i, int l, int r, int qpos, int v) {
		res[i] += v;
		if (l == r) return;
		int mid = (l + r) / 2;
		if (qpos <= mid) update(ls(i), l, mid, qpos, v);
		else update(rs(i), mid + 1, r, qpos, v);
	}
	int query(int i, int l, int r, int kth) {
		if (l >= r) return l;
		int mid = (l + r) / 2;
		if (res[ls(i)] < kth) return query(rs(i), mid + 1, r, kth - res[ls(i)]);
		else return query(ls(i), l, mid, kth);
	}
} t;

signed main() {
	freopen("permutation.in", "r", stdin); freopen("permutation.out", "w", stdout);
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> n >> r;
	if (n <= 10) {
		dfs(1);
	} else if (r == 2) {
		cout << "3 1 2 4 ";
		for (int i = 5; i <= n - 2; ++i) cout << i << " ";
		cout << n << " " << n - 1 << "\n";
	} else {
		frc[0] = 1;
		for (int i = 1; i <= 20; ++i) frc[i] = frc[i - 1] * i;
		--r;
		n -= 4;
		for (int i = 1; i <= n; ++i) t.update(1, 1, n, i, 1);
		for (int i = 1; i <= n; ++i) {
			if ((n - i) <= 20) {
				int div = r / frc[n - i] + 1;
				res[i] = t.query(1, 1, n, div);
				r %= frc[n - i];
			} else res[i] = n - i + 1;
			t.update(1, 1, n, res[i], -1);
		}
		cout << "3 1 2 4 ";
		for (int i = 1; i <= n; ++i) cout << res[i] + 4 << " \n"[i == n];
	}
}
/*
   1 2 3 4 5 6 8 7
*/
